package com.rain.service.impl;

import com.rain.enums.PageSize;
import com.rain.query.SimplePage;
import com.rain.entity.EtTower;
import com.rain.query.EtTowerQuery;
import com.rain.query.PaginationResult;
import com.rain.mapper.EtTowerMapper;
import com.rain.service.EtTowerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * @auther: rain
 * @description: 输电塔Service
 * @date: 2025-10-31
 */

@Service("etTowerService")
public class EtTowerServiceImpl implements EtTowerService{

	@Resource
	private EtTowerMapper<EtTower, EtTowerQuery> etTowerMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<EtTower> findListByParam(EtTowerQuery query) {

		return this.etTowerMapper.selectList(query);

	}

	/**
	 * 根据条件查询数量
	 */
	public Long findCountByParam(EtTowerQuery query) {

		return this.etTowerMapper.selectCount(query);

	}

	/**
	 * 分页查询
	 */
	public PaginationResult<EtTower> findListByPage(EtTowerQuery query) {

		Long count = etTowerMapper.selectCount(query);
		Integer pageNo = query.getPageNo() == null ? 1 : query.getPageNo();
		Integer pageSize = query.getPageSize() == null ? PageSize.SIZE15.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), query.getPageSize(), count);
		query.setSimplePage(simplePage);
		List<EtTower> list = etTowerMapper.selectList(query);
		PaginationResult<EtTower> result = new PaginationResult(count, simplePage.getPageNo(), simplePage.getPageSize(), simplePage.getPageTotal(),list);
		return result;

	}

	/**
	 * 新增
	 */
	public Integer add(EtTower bean) {

		return etTowerMapper.insert(bean);

	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<EtTower> listBean) {

		if(listBean == null || listBean.isEmpty()) {
		return 0;
		}
		return etTowerMapper.insertBatch(listBean);

	}

	/**
	 * 批量新增修改
	 */
	public Integer addOrUpdateBatch(List<EtTower> listBean) {

		if(listBean == null || listBean.isEmpty()) {
		return 0;
		}
		return etTowerMapper.insertOrUpdateBatch(listBean);

	}

	/**
	 * 根据Id查询
	 */
	public EtTower getEtTowerById(Integer id) {

		return etTowerMapper.selectById(id);

	}

	/**
	 * 根据Id更新
	 */
	public Integer updateEtTowerById(EtTower bean, Integer id){

		return etTowerMapper.updateById(bean, id);

	}

	/**
	 * 根据Id删除
	 */
	public Integer deleteEtTowerById(Integer id) {

		return etTowerMapper.deleteById(id);

	}

}